package study.ttl.utils;

import cn.dev33.satoken.stp.StpUtil;
import study.ttl.entity.User;
import study.ttl.service.UserService;

/**
 * Sa-Token工具类
 */
public class SaUtils {

    /**
     * 获取当前登录用户
     * @return
     */
    public static User getLoginUSer() {
        Object loginId = StpUtil.getLoginId();
        if (loginId != null) {
            Integer id = Integer.valueOf(loginId.toString());
            UserService userMapper = SpringUtils.getBean(UserService.class);
            User user = userMapper.selectById(id);
            return user;
        }
        return null;
    }
}
